package com.tanhua.server.service;

import com.tanhua.server.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

/**
 * @Author YuShiLong
 * @Date 2021/4/14 20:11
 * @Version 1.0
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${tanhua.sso.url}")
    private String ssoUrl;

    public User queryUserByToken(String token) {

        //拼接url
        String url = ssoUrl + "/user/" + token;

        User user = null;
        try {
            user = restTemplate.getForObject(url, User.class);
        } catch (RestClientException e) {
            log.error("获取user失败！", e);
        }

        return user;
    }
}
